/* GUI CONVERTED from rssdtmta.p (converter v1.75) Wed Aug 30 16:54:40 2000 */
/* rssdtmta.p - Supplier Shipping Schedule Standard Delivery Time Maint    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                     */
/* All rights reserved worldwide.  This is an unpublished work.            */
/*V8:ConvertMode=Maintenance                                               */
/*V8:RunMode=Character,Windows                                          */
/* REVISION: 9.0      CREATED:       07/13/98   By: *K1QZ* Pat McCormick   */
/* REVISION: 9.0     MODIFIED:       03/13/99   By: *M0BD* Alfred Tan      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb               */
/* REVISION: 9.1      LAST MODIFIED: 08/30/00 BY: *N0QG* Katie Hilbert     */
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

/* **************** Begin Translatable Strings Definitions **************** */

            {mfdeclre.i} /*GUI moved to top.*/
         &SCOPED-DEFINE rssdtmta_p_1 "Time"
         /* Max Len10: Comment:  */

/* ***************** End Translatable Strings Definitions ***************** */

/*GUI moved mfdeclre/mfdtitle.*/
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

            define input parameter l_sdt_recno as recid no-undo.

            define variable shiptime_recid as recid no-undo.
            define variable l_del_yn      like mfc_logical initial no no-undo.
            define variable l_curr_sdtd_recno as recid no-undo.
            define variable l_sdtd_time as character format "x(18)" no-undo.
            define variable l_ref_time as character format "99:99" no-undo.
            define variable l_dummy_length as character format "999:99" no-undo.
            define variable l_msgnbr as integer no-undo.
            define variable i as integer no-undo.

            FORM /*GUI*/ 
            space(2)
            sdtd_time format "99:99" label {&rssdtmta_p_1} space(4)
            with frame b down width 80 THREE-D /*GUI*/.


            /* SET EXTERNAL LABELS */
            setFrameLabels(frame b:handle).

            FORM /*GUI*/ 
            space(2)
            l_sdtd_time format "99:99"  label {&rssdtmta_p_1} space(4)
            with frame c down width 80 THREE-D /*GUI*/.


            /* SET EXTERNAL LABELS */
            setFrameLabels(frame c:handle).

            loopb:
            do on error undo, leave:
/*GUI*/ if global-beam-me-up then undo, leave.


                browloop:
                repeat with frame b:

                   for first sdt_mstr where recid(sdt_mstr) = l_sdt_recno
                   no-lock: end.

                   down 1 with frame b.

                   {swindar.i
                       &searchkey = sdt_mstr.sdt_code
                       &detfile = sdtd_det
                       &detkey  = sdtd_code
                       &detlink = sdtd_code
                       &mstrfile = sdt_mstr
                       &mstrkey  = sdt_code
                       &scroll-field = sdtd_time
                       &framename = "b"
                       &framesize = 5
                       &display1 = "sdtd_time"
                       &exitlabel = browloop
                       &exit-flag = false
                       &record-id = shiptime_recid
                       &go-on = "go-on (F5 CTRL-D)"
                       &statusline = stline[10]
                       &postchoosehook = "~
                       if keyfunction(lastkey) = 'insert-mode' then do:
                          l_curr_sdtd_recno = sw_frame_recid[1].
                          run add_mode(input l_sdt_recno, output shiptime_recid).
                          sw_recid =  if shiptime_recid <> ? then shiptime_recid
                                                          else l_curr_sdtd_recno.
                          next sw-main-loop.
                       end.
                       if (lastkey = keycode('CTRL-D') or
                           lastkey = keycode('F5')) and
                          sw_frame_recid[frame-line(b)] <> ? then do:
                          assign
                             shiptime_recid = sw_frame_recid[frame-line(b)].
                             l_curr_sdtd_recno = if frame-line(b) = 1
                                then sw_frame_recid[2] else sw_frame_recid[1].
                          run del_mode (input shiptime_recid,output l_del_yn).
                          if l_del_yn then
                          sw_recid = l_curr_sdtd_recno.
                          else sw_recid = shiptime_recid.
                          next sw-main-loop.
                       end."
                   }

                end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF BROWSE LOOP */

                hide frame b.
                hide frame c.

            end.  /* END OF LOOPB */

            PROCEDURE add_mode:
                define input parameter l_sdt_recno as recid no-undo.
                define output parameter shiptime_recid as recid no-undo.

                view frame b.
                add_block:
                repeat transaction on error undo, retry:

                    clear frame c no-pause.

                    for first sdt_mstr where recid(sdt_mstr) = l_sdt_recno
                    no-lock: end.

                    ststatus = stline[3].
                    status input ststatus.

                    set
                       l_sdtd_time
                    with frame c.

                    if can-find(first sdtd_det where sdtd_code = sdt_code
                                      and sdtd_time = l_sdtd_time) then
                    do:
                      /* UNABLE TO CREATE RECORD ALREADY EXISTS */
                      {mfmsg.i 2041 4}
                        undo, retry.
                    end.
                   assign
                       l_ref_time = substring(string(time,"HH:MM"),1,2)
                                  + substring(string(time,"HH:MM"),4,2)
                       l_msgnbr = 0
                       l_sdtd_time = input l_sdtd_time.

                   /* FSTIMCHK WILL RETURN ONE OF TWO POTENTIAL  */
                   /* ERRORS.  #30 IS FOR MINUTES > 59.  #69     */
                   /* INDICATES NON-NUMERIC INPUT, IN WHICH CASE */
                   /* WE WANT TO PRESERVE AND REDISPLAY THE USER */
                   /* INPUT.                                     */

                   {gprun.i ""fstimchk.p""
                            "(input  ""T"",
                              input  l_sdtd_time,
                              input  """",
                              output l_ref_time,
                              output l_dummy_length,
                              output l_msgnbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                   if l_msgnbr <> 0 then do:
                       {mfmsg.i l_msgnbr 3}
/*N0QG**                       next-prompt sdtd_time with frame d.    */
/*N0QG*/               next-prompt l_sdtd_time with frame c.
                       undo, retry.
                   end. /* END OF IF l_msgnbr <> 0 */

                    create sdtd_det.
                    assign sdtd_code = sdt_code
                           sdtd_time = l_sdtd_time
                           sdtd_mod_userid = global_userid
                           sdtd_mod_date = today
                           shiptime_recid = recid(sdtd_det).

                           if recid(sdtd_det) = -1 then .

                    display
                        sdtd_time @ l_sdtd_time
                    with frame c.

                   /* CLEAR MIDDLE FRAME */
                   clear frame b all no-pause.

                   /* FIND CURRENT COMMODITY/PART RECORD */
                   for first sdtd_det where
                       recid(sdtd_det) = shiptime_recid no-lock:
                   end.

                   /* FIND POSITION IN FILE TO DISPLAY FULL FRAME */
                   if available (sdtd_det) then do:
                       do i = 1 to truncate(frame-down(b) / 2,0)
                       while available sdtd_det:
                           find next sdtd_det where
                               sdtd_code = sdt_code no-lock no-error.
                       end.
                       if not available (sdtd_det) then do:
                           find last sdtd_det where
                               sdtd_code = sdt_code no-lock no-error.
                       end.
                       do i = 1 to frame-down(b) - 1 while available sdtd_det:
                           find prev sdtd_det where
                               sdtd_code = sdt_code no-lock no-error.
                       end.
                       if not available sdtd_det then do:
                           find first sdtd_det where
                               sdtd_code = sdt_code no-lock no-error.
                       end.
                   end.
                   else do:
                       find first sdtd_det where
                           sdtd_code = sdt_code no-lock no-error.
                   end.

                   /* BUILD MIDDLE FRAME */
                   if available sdtd_det then do:
                       do i = 1 to frame-down(b) while available sdtd_det:
                           display
                               sdtd_time
                           with frame b.

                           find next sdtd_det where
                               sdtd_code = sdt_code no-lock no-error.

                           if frame-line(b) < frame-down(b) then
                               down 1 with frame b.
                       end.
                   end.

                end . /* END OF add_block */
                hide frame c no-pause.

            END PROCEDURE. /* PROCEDURE add_mode */

            PROCEDURE del_mode:
                define input parameter shiptime_recid as recid no-undo.
                define output parameter l_del_yn like mfc_logical no-undo.

                del-loop:
                do transaction on endkey undo, leave:

                    for first sdtd_det where recid(sdtd_det) = shiptime_recid
                    exclusive-lock: end.

                    display
                       sdtd_time @ l_sdtd_time
                    with frame c.

                    l_del_yn = yes.

                    /* DO YOU WANT TO DELETE THE RECORDS ? */
                    {mfmsg01.i 11 1 l_del_yn}
                    if not l_del_yn then undo del-loop, leave del-loop.

                    if l_del_yn then do:
                        delete sdtd_det.
                    end.

                end. /* END OF del-loop */
                hide frame c.

            END PROCEDURE. /* PROCEDURE del_mode */
